﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using DbCommon;

namespace Web.UI
{
    public class checkrepeat
    {

        /// <summary>
        /// 获得所有的重复项
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int checkrepeatCount(BoCheckRepat model )
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select count(*) from ");
            sql.Append(model.tablename);
            sql.Append(" where 1=1 ");
            if (!string.IsNullOrEmpty(model.constr))
            {
                sql.Append(" and ");
                sql.Append(model.constr);
                sql.Append(" ='true' ");
            }
            foreach (DictionaryEntry de in model.content)
            {
                sql.Append(" and ");
                sql.Append(de.Key.ToString());
                sql.Append("=@");
                sql.Append(de.Key.ToString());
            }
            SqlParameter[] parameter = new SqlParameter[model.content.Count];
            int i = 0;
            foreach (DictionaryEntry de in model.content)
            {
                SqlParameter pr = new SqlParameter("@" + de.Key.ToString(), de.Value.ToString());
                parameter[i] = pr;
                i++;
            }
            DbHelper helper = new DbHelper();
            return (int)helper.ExcuteQuery(sql.ToString(), parameter).Rows[0][0];
        }

    }
}
